package com.itheima.web;

import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkitem")
@Api(tags = "检查项")
public class CheckItemController {

    @Reference //生成代理对象  搜集接口信息
    private CheckItemService checkItemService;

/*
    @ApiOperation("新增检查项")
    @PostMapping("/add")
    public boolean add(@RequestBody CheckItem checkItem){
        return checkItemService.save(checkItem);
    }
*/

    @ApiOperation("查询所有")
    @GetMapping("/findAll")
    public List<CheckItem> findAll(){
        //过滤条件  is_delete=0
        return checkItemService.findAll();
    }

    @ApiOperation("按照id删除")
    @GetMapping("deleteById/{id}")
    public Boolean deleteById(@PathVariable("id") Long id){
        return checkItemService.deleteById(id);
    }

    @PostMapping("/saveOrUpdate")
    public boolean saveOrUpdate(@RequestBody CheckItem checkItem){
        //第一步根据主键查询数据是否存在
        //第二部  如果存在 则修改数据
        return checkItemService.saveOrUpdate(checkItem);
    }

    @PostMapping("/findByPage")
    public PageResult findByPage(@RequestBody QueryPageBean pageBean){

        return checkItemService.findByPage(pageBean);
    }

    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean pageBean){

        return checkItemService.findPage(pageBean);
    }


}
